import {defineStore} from 'pinia';
import {Http, Cache, Helper, Constant, Msg} from 'core';
import userStore from '@/stores/framework/user';

const UserStore = userStore();
const store = {
    id: "aliyun",
    state() {
        return {
            companyConfig: {},

            companyInfo: {}
        }
    },

    getters: {},

    actions: {
        /**
         * 支付
         * @param tradeNo
         * @returns {Promise<unknown>}
         */
        async tradePay(tradeNo) {
            return new Promise((resolve, reject) => {
                my.tradePay({
                    tradeNO: tradeNo,
                    success: (res) => {
                        if (res.resultCode == 9000) {
                            Msg.success("处理成功");
                            resolve(true);
                            return;
                        }
                        Msg.error("处理失败，状态码：" + res.resultCode)
                        resolve(false);
                    },
                    fail: (err) => {
                        Msg.error("发起支付异常:" + (typeof err == 'object' ? JSON.stringify(err) : err));
                        resolve(false);
                    }
                })
            })
        },

        /**
         * 申请签约签名串
         * @returns {Promise<string|*>}
         */
        async applySign() {
            Msg.loading("加载中...")
            let {code, data} = await Http.get("/appuser/toSign4Withhold")
            Msg.loading(false);
            if (code == 200) {
                return data;
            }
            return "";
        },

        /**
         * 检查是否已签约
         * @returns {Promise<boolean|*>}
         */
        async checkSign() {
            Msg.loading("加载中...")
            let {code, data} = await Http.get("/appuser/toCheck4Withhold")
            Msg.loading(false);
            if (code == 200) {
                return data;
            }
            return false;
        },


    }
}

export default defineStore(store)
